﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using DataLib.Common;
using DataLib.Accounts.Bus;

namespace Ewts.BaseData
{
    public partial class VehiclorModify : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                dropCity.DataSource = new DataLib.BLL.City().GetList("flag1='02'").Tables[0];
                dropCity.DataTextField = "cityname";
                dropCity.DataValueField = "citycode";
                dropCity.DataBind();

                if (Request["id"] != null && Request["id"].ToString().Trim() != "")
                {
                    int id = (Convert.ToInt32(Request["id"].ToString().Trim()));
                    ShowInfo(id);
                }
            }
        }

        private void ShowInfo(int id)
        {
            DataLib.BLL.Vehiclor bll = new DataLib.BLL.Vehiclor();
            DataLib.Model.Vehiclor model = bll.GetModel(id);
            this.txtid.Value = model.id.ToString();
            dropCity.SelectedItem.Text = model.city;
            this.txtname.Text = model.name;
            this.txtUserName.Text = model.emploeeno;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
           
            if (this.txtname.Text.Trim().Length == 0)
            {
                strErr += "收货员姓名不能为空！\\n";
            }
         

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int id = int.Parse(this.txtid.Value);
            string city = dropCity.SelectedItem.Text;
            string name = this.txtname.Text;
            string emploeeno = this.txtUserName.Text;


            DataLib.Model.Vehiclor model = new DataLib.Model.Vehiclor();
            model.id = id;
            model.city = city;
            model.name = name;
            model.emploeeno = emploeeno;

            DataLib.BLL.Vehiclor bll = new DataLib.BLL.Vehiclor();
            bll.Update(model);
            DataLib.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "VehiclorList.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("VehiclorList.aspx");
        }
    }
}
